﻿
	<title>Thông tin chi tiết thuê phòng</title>	
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" type="text/css" href="../../../lib/css/layout.css"/>
	<link  rel="stylesheet" type="text/css" href="../../../lib/css/jquery-ui-1.8.6.custom.css" />
	<link rel="stylesheet" href="../../../lib/css/smartui.css"/>
	<link rel="stylesheet" href="../../../lib/css/general.css"/>
	<link rel="stylesheet" href="../../../lib/css/jquery.treeview.css"/>
	
    <script src="../../../lib/jquery-1.4.4.min.js" type="text/javascript"></script>
	<script src="../../../lib/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../../lib/jquery.treeview.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../../lib/demo.js"></script>
    <script type="text/javascript" src="../../../lib/common.js"></script>
	<script type="text/javascript" src="../../../lib/datetimepicker_css.js"></script>
    <script type="text/javascript" src="../../../lib/jquery-ui-1.8.6.custom.min.js"></script>
	<script type="text/javascript" src="../../../lib/picnet.js"></script>
    <script type="text/javascript" src="../../../lib/ajaxfileupload.js"></script>
    
    <script type="text/javascript" src="../../../lib/highcharts.js"></script>
	<script type="text/javascript" src="../../../lib/exporting.js"></script>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
	
<table class="ctable" id="bookroom" width="99%">
<tr class="title">
	<td colspan="6" align=left>会議室情報</td>
</tr>
<?php
session_start ();
$order_id = $_REQUEST ['order_id'];
include_once '../../Model/Room.php';
$room = new Room ();
$rs = $room->get_user_room_id($order_id);
//TODO
if ($rs != NULL) {
	$result = '';
	for($i = 0; $i < count ( $rs ); $i ++) {		
		$result = $result . '<tr height=30px><td width="10%" align=right><b>室名:</b></td>';		
		$result = $result . '<td width="15%"> <label id="lbRoomName">'.$rs[$i]['room_name'].'</label></td>';		
		$result = $result . '<td align=right width="10%"><b>椅子の定数:</b></td>';		
		$result = $result . '<td width="10%"> <label id="lbChair">'.$rs[$i]['chair'].' Chiếc</label></td>';		
		$result = $result . '<td width="5%" align=right><b>料金:</b></td>';		
		$result = $result . '<td width="25%"> <label id="lbPrice">'.$rs[$i]['price'].' VND</label></td></tr>';		
		$result = $result . '<tr height=30px><td align=right><b>会議室の詳細情報:</b></td>';		
		$result = $result . '<td colspan=5> <label id="lbDescription">'.$rs[$i]['description'].'</label></td></tr>';
	}	
	echo $result;
}
?>
</table>
<table class="ctable" id="tblPutRoom" width="99%">
<tr class="title">
	<td colspan="4" align=left>予約者情報</td>
</tr>
<tr><td colspan="4" align="center"><div id="inform"></div></td></tr> 
<tr height="25px">
	<td align=right width="15%">アカウント名: </td>
	<td width="40%">
		<input type="text" id="txtUsername" name="txtUsername" class="cinput" value="<?php echo $rs[0]['username'];?>" disabled/>
	</td>
	<td align=right width="15%">ユーザ名: </td>
	<td width="30%">		
		<b><?php echo $rs[0]['name'];?></b>		
	</td>
</tr>
<tr height="25px">
	<td align=right>アドレス: </td>
	<td>
		<b><?php echo $rs[0]['address'];?></b>
	</td>
	<td align=right>メール: </td>
	<td>
		<b><?php echo $rs[0]['email'];?></b>
	</td>
</tr>
<tr height="25px">
	<td align=right>携帯電話番号: </td>
	<td>
		<b><?php echo $rs[0]['mobi'];?></b>
	</td>
	<td align=right>電話番号: </td>
	<td>
		<b><?php echo $rs[0]['tell'];?></b>
	</td>
</tr>
<tr height="25px">
	<td align=right>室名: </td>
	<td>
		<select id="slRoom" style="width: 30%;">
		<?php
			$rsRoom= $room->get_list_room_all(); 
			for($i=0;$i<count($rsRoom);$i++){
				if($rs[0]['room_id'] == $rsRoom[$i]['id']){
					echo '<option selected value="'.$rsRoom[$i]['id'].'">'.$rsRoom[$i]['name'].'</option>';
				}else{
					echo '<option value="'.$rsRoom[$i]['id'].'">'.$rsRoom[$i]['name'].'</option>';
				}    			
			}		
		?>
		</select>
		
	</td>
	<td align=right>料金: </td>
	<td>
		<input id="txtPrice" name="txtPrice" class="cinput" value="<?php echo $rs[0]['total'];?>"></input>(VND)
	</td>
</tr>
<tr height="25px">
	<td align=right>予約年月日: </td>
	<td>
		<input type="text" value="<?php echo $rs[0]['date'];?>" id="putDate" name="putDate" class="cdate" style="width: 40%" ></input>
	</td>
	<td align=right>状態: </td>
	<td>
		<select id="slStatus" style="width: 100px;">
		<?php 
		$hh = 0;	$kk = '';
		for($i=0;$i<=2;$i++){			
			if($i == $rs[0]['status']){
				$option = '<option selected value="';
			}else{
				$option = '<option value="';	
			}
			if($i==0){
				$option = $option.$i.'">キャンセルする</option>';	
			}if($i==1){
				$option = $option.$i.'">予約する</option>';	
			}if($i==2){
				$option = $option.$i.'">終わる</option>';	
			}
			echo $option;
		}	
		?>
		</select>
	
	</td>
</tr>
<tr >
	<td align=right>スタート時間: </td>
	<td> 
		<select id="timeStart" style="width: 100px;">
		<?php 
		$hh = 0;	$kk = '';
		for($i=0;$i<=47;$i++){
			if($i%2 == 0){
				if($hh>=0 && $hh<=9){
					$kk = '0'.$hh.':00';
				}else{
					$kk = $hh.':00';
				}					
			}else{
				if($hh>=0 && $hh<=9){
					$kk = '0'.$hh.':30';
				}else{
					$kk = $hh.':30';
				}
				$hh++;
			}
			
			if($hh == $rs[0]['start_time']){
				echo '<option value="'.$kk.'" selected>'.$kk.'</option>';	
			}else{
				echo '<option value="'.$kk.'">'.$kk.'</option>';	
			}
		}	
		?>
		</select>
	</td>
	<td align=right>エンド時間: </td>
	<td>
		<select id="timeEnd" style="width: 100px;">
		<?php 
		$hh = 0;	$kk = '';
		for($i=0;$i<=47;$i++){
			if($i%2 == 0){
				if($hh>=0 && $hh<=9){
					$kk = '0'.$hh.':00';
				}else{
					$kk = $hh.':00';
				}					
			}else{
				if($hh>=0 && $hh<=9){
					$kk = '0'.$hh.':30';
				}else{
					$kk = $hh.':30';
				}
				$hh++;
			}
			
			if($hh == $rs[0]['end_time']){
				echo '<option value="'.$kk.'" selected>'.$kk.'</option>';	
			}else{
				echo '<option value="'.$kk.'">'.$kk.'</option>';	
			}
		}	
		?>
		</select>
	</td>	
</tr>
<tr>
	<td align="right">罰金:</td>
	<td>
		100,000 VND/３０分
	</td>
	<td align="right">処罰される時間:</td>
	<td>
		<input type="text" id="txtTimeExpired" name="txtTimeExpired" value="<?php echo $rs[0]['time_expired'];?>"/>
	</td>
</tr>
<tr height="30px">
	<td width="15%" align="center" colspan=4>
		<input type="button" class="cbutton" id="btnSave" name="btnSave" value="保存する" style="width: 80px; height: 21px;"/>&nbsp;
		<input type="button" class="cbutton" id="btnClose" name="btnClose" value=" ウィンドウズ " style="width: 80px; height: 21px;"/>
	</td>
</tr>
</table>
<br><div id="container" style="width: 99%; height: 320px;"></div>

<input type="hidden" value="<?php echo $rs[0]['start_time'];?>" id="hidStartTime" name="hidStartTime"/>
<input type="hidden" value="<?php echo $rs[0]['room_id'];?>" id="hidRoomID" name="hidRoomID"/>
<input type="hidden" value="<?php echo $_REQUEST['type'];?>" id="hidType" name="hidType"/>
<input type="hidden" value="<?php echo $order_id;?>" id="hidID" name="hidID"/>
<input type="hidden" value="<?php echo $rs[0]['price'];?>" id="hidPrice" name="hidID"/>
<input type="hidden" value="<?php echo $rs[0]['status'];?>" id="hidStatus" name="hidStatus"/>
<input type="hidden" value="10000" id="hidPrice2" name="hidID2"/>

<script type="text/javascript">
//Tao doi tuong bieu do
var chart;
//Danh sach truc X
var listX = ['21/03','20/03','19/03','<label style="color:red;">18/03</label>','17/03','16/03','15/03'];
//Danh sach truc Y
var listY = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24];
//Du lieu
///
var list;
/**
 * Grid theme for Highcharts JS
 * @author Torstein H𮳩
 */
Highcharts.theme = {
   colors: ['#DDDF00','#FF0000','#DDDF00','#FF0000','#DDDF00','#FF0000','#DDDF00','#FF0000','#DDDF00'],
   chart: {
	  backgroundColor: {
		 linearGradient: [0, 0, 500, 500],
		 stops: [
			[0, '#AAAAAA'],
			[1, '#AAAAAA']
		 ]
	  },
	  borderWidth: 2,
	  plotBackgroundColor: '#FFFFFF',
	  plotShadow: true,
	  plotBorderWidth: 0
   },
   title: {
	  style: {
		 color: '#000',
		 font: 'bold 16px "Tahoma", Tahoma, Tahoma'
	  }
   },
   tooltip: {
		style: {
		 color: '#000',
		 font: '16px "Tahoma", Tahoma, Tahoma'
	    }
	},
   subtitle: {
	  style: {
		 color: '#666666',
		 font: 'bold 12px "Tahoma", Tahoma, Tahoma'
	  }
   },
   xAxis: {
	  gridLineWidth: 1,
	  lineColor: '#000',
	  tickColor: '#000',
	  labels: {
		 style: {
			color: '#000',
			font: 'bold 13px Tahoma, Tahoma, Tahoma'
		 }
	  },
	  title: {
		 style: {
			color: '#333',
			fontWeight: 'bold',
			fontSize: '12px',
			fontFamily: 'Tahoma, Tahoma, Tahoma'
		 }
	  }
   },
   yAxis: {
	  minorTickInterval: 'auto',
	  lineColor: '#000',
	  lineWidth: 0,
	  tickWidth: 0,
	  tickColor: '#000',
	  labels: {
		 style: {
			color: '#000',
			font: 'bold 11px Tahoma, Tahoma, Tahoma'
		 }
	  },
	  title: {
		 style: {
			color: '#333',
			fontWeight: 'bold',
			fontSize: '12px',
			fontFamily: 'Tahoma, Tahoma, Tahoma'
		 }
	  }
   },
   labels: {
	  style: {
		 color: '#99b'
	  }
   }
};

// Apply the theme
var highchartsOptions = Highcharts.setOptions(Highcharts.theme);	

function process(date){
   var parts = date.split("/");
   var date = new Date(parts[1] + "/" + parts[0] + "/" + parts[2]);
   return date.getTime();
}
$(document).ready(function() {	
	if($('#hidType').val() == 'view' || $("#hidStatus").val() == 0 || $("#hidStatus").val() == 2){
		$("#btnSave").hide();
	}

	
	$("#putDate").datepicker({dateFormat:"dd/mm/yy"});
	chartTimeline();
	
	$('#putDate').change(function(e){
		chartTimeline();
	});	
		
	$("#timeStart").change(function(e){				
		xx = $("#hidPrice").val()*($("#timeEnd").attr("selectedIndex")-$("#timeStart").attr("selectedIndex"))+parseInt($("#hidPrice2").val());
		$("#txtPrice").val(xx);
	});
	
	$("#timeEnd").change(function(e){
		$("#inform").html('');
		if($("#timeStart").attr("selectedIndex") > $("#timeEnd").attr("selectedIndex")){
			_alert("inform","Thời gian bắt đầu phải nhỏ hơn thời gian kết thúc!");
			$("#timeEnd").attr("selectedIndex",0);
			return;
		}
						
		xx = $("#hidPrice").val()*($("#timeEnd").attr("selectedIndex")-$("#timeStart").attr("selectedIndex"))+parseInt($("#hidPrice2").val());
		$("#txtPrice").val(xx);
	});
	
	$('#slRoom').change(function(e){
		$("#hidRoomID").val($('#slRoom').val());
		chartTimeline();
	});	
	
	$("#btnSave").click(function(){
		var $id = $("#hidID").val();
		var room_id = $("#hidRoomID").val();
		var status = $("#slStatus").val();
		var time_start = $("#putDate").val().replace(/ /gi, "")+" "+$("#timeStart").val();
		var time_end = $("#putDate").val().replace(/ /gi, "")+" "+$("#timeEnd").val();
		var price = $("#txtPrice").val();
		var time_expired = $("#txtTimeExpired").val();
		
		var now = new Date();
		dd2 = now.getDate();
		mm2 = now.getMonth()+1;
		yy2 = now.getFullYear();
		now = new Date(dd2+"/"+mm2+"/"+yy2);
		var date = new Date($("#putDate").val().replace(/ /gi, ""));
		zz = now.getTime();
		xx = date.getTime();
		
		if($("#putDate").val().replace(/ /gi, "") == ""){
			_alert("inform","Ngày đặt phòng không được rỗng!");
			return;	
		}else if(zz > xx){
			_alert("inform","Thời gian đặt phòng phải lớn hơn hoặc bằng thời gian hiện tại!");
			return;
		}else if($("#timeStart").attr("selectedIndex") > $("#timeEnd").attr("selectedIndex")){
			_alert("inform","Thời gian bắt đầu phải nhỏ hơn thời gian kết thúc!");
			$("#timeStart").attr("selectedIndex",0);
			return;
		}else if(isNaN(time_expired)){
			_alert("inform","Thời gian quá hạn phải là số!");
			return;
		}
		
		var path = 'id='+$id+'&room_id='+room_id+'&status='+status+''
			+'&timeStart='+time_start+'&timeEnd='+time_end+'&price='+price+'&time_expired='+time_expired;
		
		$.ajax({
  			type:"POST",
  			url: "update_put_room.php",
  			data: path,
            async: true,
			success: function(data) {
				_alert("inform",data);
				chartTimeline(); 		
				opener.get_list_user_room(room_id,1);			
		     }
	    }); 
	});

	//Dong cua so
	$("#btnClose").click(function(){
		window.close();
	});	
}); 	

function chartTimeline(){
	var room_id = $("#hidRoomID").val();	
	var path='room_id='+room_id+'&date='+$("#putDate").val().replace(/ /gi, "");
	$.ajax({
		type:"POST",
		url: "get_timeline.php",
		data: path,
        async: false,
		success: function(data) { 		
			arrData = data.split('(*)');
			listX = arrData[0].split(',');;
			list = $.parseJSON(arrData[1]);			
			//_alert("inform",data);
			chart = new Highcharts.Chart({
				chart: {
					renderTo: 'container',
					type: 'bar'
				},
				title: {
					text: '時間'
				},
				xAxis: {
					categories: listX,
					title: {
						text: '予約年月日'
					}
				},
				yAxis: {
					categories: listY,
					min: 0,
					max: 24,
					title: {
						text: '時間'
					}
				},
				tooltip: {
					formatter: function() {
						return ''+ this.series.name
					}
				},
				plotOptions: {
					series: {
						stacking: 'normal'
					}
				},
				legend: {
					enabled: false
			    },
			    series: list
			});
     	}
    }); 	
}

//
function convertTimeToNumber(time){	
	hh = mm = 0;
	hh = parseInt(time.substring(0, 2))*2;	
	mm = parseInt(time.substring(3, 5)) + 0;
	if(mm == 0 || time.substring(3, 5) == '00'){
		return hh;
	}else{
		return hh+1;
	}
}
</script>